package com.baizhi.service.impl;

import com.baizhi.dao.ProductDao;
import com.baizhi.entity.Product;
import com.baizhi.service.ProductService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao;

    public void setProductDao(ProductDao productDao) {
        this.productDao = productDao;
    }

    @Override
    public int addProduct(Product p) {
        int i = productDao.insertProduct(p);
        return i;
    }

    @Override
    public int deleteOneProduct(Integer pid) {
        int i= productDao.deleteOneProduct(pid);
        return i;
    }

    @Override
    public int deleteAnyProduct(Integer[] pids) {
        int i = productDao.deleteAnyProduct(pids);
        return i;
    }

    @Override
    public int updateProduct(Product p) {
        int i = productDao.updateProduct(p);
        return i;
    }

    @Override
    public Product selectById(Integer pid) {
        Product product = productDao.selectById(pid);
        return product;
    }

    @Override
    public List<Product> selectProductByCondition(String pname, Double price, Integer pageNum, Integer pageSize) {
        Integer start = (pageNum-1)*pageSize;
        List<Product> list = productDao.selectProductByCondition(pname, price, start, pageSize);
        return list;
    }

    @Override
    public int totalProduct(String pname, Double price) {
        int i = productDao.totalProduct(pname,price);
        return i;
    }
}
